package com.ssy.lingxi.member.merchant.model.constant;

import com.ssy.lingxi.common.constant.member.BusinessCategoryInvoiceTypeEnum;
import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.DropdownItem;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 预付款枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-25
 */
public enum AdvanceChargeEnum {

    /**
     * 预付款：1:不需预付 2：需要预付
     */

    /**
     * 1、不需预付
     */
    NO_PREPAYMENT(1, "不需预付"),

    /**
     * 2、需要预付
     */
    YES_PREPAYMENT(2, "需要预付");

    AdvanceChargeEnum(Integer code, String msg) {
        this.code = code;
    }

    private final Integer code;

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public static List<DropdownItem> toDropdownList() {
        List<DropdownItem> items = Arrays.stream(AdvanceChargeEnum.values()).sorted(Comparator.comparingInt(AdvanceChargeEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
        items.add(0 , new DropdownItem(0, MemberStringEnum.CHOOSE.getName()));
        return items;
    }

    public static List<DropdownItem> toEditableDropdownList() {
        return Arrays.stream(AdvanceChargeEnum.values()).sorted(Comparator.comparingInt(AdvanceChargeEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
    }

    public static String getCodeMsg(Integer code) {
        return LanguageHolder.getName(AdvanceChargeEnum.class, code);
    }

    /**
     * 根据枚举值获得名称
     * @param code 枚举值
     * @return 发票名称
     */
    public static String getNameByCode(Integer code) {
        return LanguageHolder.getName(AdvanceChargeEnum.class, code);
    }
}
